namespace hemsidan.GUIControls
{
	using System;
	using System.Data;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;

	/// <summary>
	///		Summary description for RecentShortBlogs.
	/// </summary>
	public partial class RecentShortBlogs : System.Web.UI.UserControl
	{

		protected void Page_Load(object sender, System.EventArgs e)
		{
			if (!IsPostBack)
				LoadData();
		}
		private void LoadData()
		{
			this.myBlogRepeater.DataSource = Entities.Blog.GetRecent(4);
			this.myBlogRepeater.DataBind();
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.myBlogRepeater.ItemDataBound += new RepeaterItemEventHandler(myBlogRepeater_ItemDataBound);
		}
		#endregion

		private void myBlogRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
		{
			int ingressLength = 200;
			Literal ingress = (Literal)e.Item.FindControl("blogIngress");
			if (ingress.Text.Length > ingressLength)
				ingress.Text = ingress.Text.Substring(0, ingress.Text.Substring(0,ingressLength).LastIndexOf(" ")) + "...";
		}
	}
}
